<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="请输入用户手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="邀请人用户ID" prop="inviteUserId">
        <el-input v-model="queryParams.inviteUserId" placeholder="邀请人用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="邀请人用户昵称" prop="inviteNickName">
        <el-input v-model="queryParams.inviteNickName" placeholder="邀请人用户昵称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="邀请人用户手机号" prop="inviteUserPhone">
        <el-input v-model="queryParams.inviteUserPhone" placeholder="邀请人用户手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="orderheadList" style="width: 100%">
      <el-table-column label="用户ID" prop="userId">
      </el-table-column>
      <el-table-column label="用户昵称" prop="nickName">
      </el-table-column>     
      <el-table-column label="用户手机号" prop="userPhone">
      </el-table-column> 
      <el-table-column label="邀请人用户ID" prop="inviteUserId">
      </el-table-column>
      <el-table-column label="邀请人用户昵称" prop="inviteNickName">
      </el-table-column>
      <el-table-column  label="邀请人用户手机号" prop="inviteUserPhone">
      </el-table-column>
      <el-table-column label="成功邀请数量" prop="inviteCount">
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看详细</el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
        <el-table :data="inviteUserIdList" style="width: 100%">
      <el-table-column label="被邀请人用户ID" prop="userId">
      </el-table-column>
      <el-table-column label="被邀请人用户昵称" prop="nickName">
      </el-table-column>
      <el-table-column  label="被邀请人用户手机号" prop="userPhone">
      </el-table-column>
      <el-table-column label="注册时间" prop="crTime">
      </el-table-column>
    </el-table>
    
    <pagination v-show="inviteTotal>0" :total="inviteTotal" :page.sync="queryListParams.pageNum" :limit.sync="queryListParams.pageSize"
        @pagination="getInviteList" />
      </el-dialog>

  </div>
</template>
<script>
  import {
    inviteMgmtList,
    invitedList
  } from "@/api/store/invite";

  export default {
    name: "Orderhead",
    dicts: ['con_value_behavior', ],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单表头表格数据
        orderheadList: [],
        // 弹出层标题
        title: "详情",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          nickName: null,
          userPhone: null,
          inviteUserId: null,
          inviteNickName: null,
          inviteUserPhone: null
        },
        queryListParams: {
          pageNum: 1,
          pageSize: 10,
          inviteUserId:""
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        dateRange: [],
        inviteUserIdList:[],
        inviteTotal:0,
        inviteUserId:''
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getStatus(res) {
        return res === '0' ?
          '待付款' :
          res === '5' ?
          '待发货' :
          res === '1' ?
          '待发货' :
          res === '6' ?
          '已发货' :
          res === '2' ?
          '已发货' :
          res === '3' ?
          '完成' :
          res === '4' ?
          '售后' :
          res === '7' ?
          '完成' :
          res === '8' ?
          '退款' :
          res === '9' ?
          '退货退款' :
          res === '10' ?
          '交易关闭' :
          '其他'
      },
      /** 查询订单表头列表 */
      getList() {
        let params = {
          userId: this.queryParams.userId,
          nickName: this.queryParams.nickName,
          userPhone: this.queryParams.userPhone,
          inviteUserId: this.queryParams.inviteUserId,
          inviteNickName: this.queryParams.inviteNickName,
          inviteUserPhone: this.queryParams.inviteUserPhone,
          pageSize: this.queryParams.pageSize,
          pageNum: this.queryParams.pageNum
        }
        inviteMgmtList(params).then(res => {
          if (res.code == '200') {
            this.orderheadList = res.rows
          }
          this.total = res.total
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          orderSerial: null,
          userId: null,
          addressId: null,
          totalAmount: null,
          couponFlag: null,
          coupon: null,
          actualAmount: null,
          emsFlag: null,
          emsFreight: null,
          orderStatus: null,
          successFlag: null,
          paySerial: null,
          orderTime: null,
          payTime: null,
          payMethods: null,
          deliveryMethod: null,
          orderRemark: null,
          invoiceFlag: null,
          delFlag: null,
          crTime: null,
          upTime: null,
          headFeild1: null,
          headFeild2: null,
          headFeild3: null,
          headFeild4: null,
          headFeild5: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = []
        this.queryParams.maxNum = null
        this.queryParams.ruleId = null
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.orderSerial)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.orderSerial != null) {
              updateOrderhead(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addOrderhead(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      handleView(row){
        this.inviteUserId = null
        this.inviteUserId = row.userId
        this.getInviteList()
      },
      getInviteList(){
        let params = {
          inviteUserId: this.inviteUserId,
          pageSize: this.queryListParams.pageSize,
          pageNum: this.queryListParams.pageNum
        }
        invitedList(params).then(response => {
          if (response.code == '200') {
            this.open = true
            this.inviteUserIdList = response.rows
          }
          this.inviteTotal = response.total      
          console.log(this.inviteTotal,'this.inviteTotalthis.inviteTotalthis.inviteTotal')    
        });
      }

    }
  };
</script>
<style>
  .br /deep/ .el-descriptions__header {
    display: none !important;
  }

  .ec-input-range-divider {
    width: 10px;
    height: 2px;
    background-color: #333;
    margin: 0 auto;
  }
</style>
